package com.dexilaonian.utils;

import android.content.Context;
import android.text.TextUtils;
import android.widget.ImageView;

import com.dexilaonian.R;
import com.squareup.picasso.Picasso;

import java.io.File;

/**
 * Created by Administrator on 2016-07-20.
 */
public class ImageLoader1 {
    /**
     * 图像显示
     *
     * @param context
     * @param picUrl
     * @param image_iv
     */
    public static void display(Context context, String picUrl, ImageView image_iv) {
        if (TextUtils.isEmpty(picUrl)) {
            image_iv.setImageResource(R.drawable.pic_loading);
            return;
        }
        Picasso.with(context).load(picUrl)
                .placeholder(R.drawable.pic_loading)
                .error(R.drawable.pic_loading).into(image_iv);
    }
    /**
     * @param context
     * @param picUrl
     * @param image_iv
     * @param wid
     * @param hei
     */
    public static void display(Context context, String picUrl, ImageView image_iv, int wid, int hei) {
        if (TextUtils.isEmpty(picUrl)) {
            image_iv.setImageResource(R.drawable.pic_loading);
            return;
        }
        Picasso.with(context)
                .load(picUrl)
                .placeholder(R.drawable.pic_loading).error(R.drawable.pic_loading)
                .resize(wid, hei)
                .into(image_iv);
    }

    /**
     * 展示大图，不加入缓存不加入内存
     *
     * @param context
     * @param imageUrl
     * @param image_iv
     */
    public static void diaplayBigImage(Context context, String imageUrl, ImageView image_iv) {
        if (TextUtils.isEmpty(imageUrl)) {
            image_iv.setImageResource(R.drawable.pic_loading);
            return;
        }
        Picasso.with(context)
                .load(imageUrl)
              //  .memoryPolicy(MemoryPolicy.NO_CACHE, MemoryPolicy.NO_STORE)
                .into(image_iv);
    }
    /**
     * 展示本地图片文件
     *
     * @param context
     * @param picPath
     * @param image_iv
     */
    public static void displayFilePath(Context context, String picPath, ImageView image_iv) {
        if (TextUtils.isEmpty(picPath)) {
            image_iv.setImageResource(R.drawable.pic_loading);
            return;
        }
        Picasso.with(context).load(new File(picPath))
                .placeholder(R.drawable.pic_loading)
                .error(R.drawable.pic_loading).into(image_iv);
    }

}
